import logging
from flask import Flask
from relex.model import db
from relex.routes.lexdoc import lexdoc_blue
from relex.routes.lexdoctype import lexdoctype_blue


app = Flask(__name__)
app.config.from_pyfile('relex.cfg')
app.register_blueprint(lexdoc_blue)
app.register_blueprint(lexdoctype_blue)
db.init_app(app)

handler = logging.FileHandler('relex.log')
loggers = [app.logger, logging.getLogger('sqlalchemy')]
for logger in loggers:
	logger.addHandler(handler)

def create_tables():
	with app.app_context:
		db.create_all()

def drop_tables():
	with app.app_context:
		db.drop_all()

if __name__ == '__main__':
	app.run(host='0.0.0.0')
	create_tables()
